package com.yunfangdata.web.controller;

import com.yunfangdata.domain.LeaveStu;
import com.yunfangdata.query.LeaveStuQueryObject;
import com.yunfangdata.service.ILeaveStuService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 徐飞 on 2018/7/7.
 */
@Controller
@RequestMapping("leavestu")
public class LeaveStuController {

    @Autowired
    private ILeaveStuService leavestuService;


    @RequestMapping("")
    public String index(){
        return "leavestu/list";
    }


    @RequestMapping("list")
    @ResponseBody
    public PageResult list(LeaveStuQueryObject qo){
        return leavestuService.query(qo);
    }

   @RequestMapping("save")
    @ResponseBody
    public JsonResult save(LeaveStu entity) {
        JsonResult result = new JsonResult();
        try{
            leavestuService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return  result;
    }


    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(LeaveStu entity) {
        JsonResult result = new JsonResult();
        try{
            leavestuService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return  result;
    }
   @RequestMapping("changeState")
    @ResponseBody
    public JsonResult changeState(Long id) {
        JsonResult result = new JsonResult();
        try{
            leavestuService.changeState(id);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("审核失败");
        }
        return  result;
    }

    //查询退款金额
    @RequestMapping("selecttotal")
    @ResponseBody
    public List<LeaveStu> selecttotal(){
        return leavestuService.list();
    }


}